 
// Object.defineProperty(exports, "__esModule", {
//   value: true
// });
// exports.default = 
Page({
  onShow: function () {
    wx.hideTabBar({})
  },
  onLoad: function () {
   
  },
    data: {
      accountNumber: "",
      password: "",
      //rpassword: "",
      email:"",
      isaccountNumber: false,
      ispassword: false,
      isemail:false
    },

 accountNumber: function accountNumber(e) {
    this.setData({ accountNumber: e.detail.value });
  },
  password: function password(e) {
    this.setData({ password: e.detail.value });
  },
  rpassword: function rpassword(e) {
    this.setData({ rpassword: e.detail.value });
  },
  email:function email(e){
    this.setData({ email: e.detail.value });
  },
  register:function register(){
    var that = this;
    if (that.data.accountNumber == "") 
    {
        wx.showModal({
            title: "错误",
            content: "账号不能为空"
        });
      that.isaccountNumber = false;
    }
    else if(!/^\d{9}$/.test(that.data.accountNumber))
    {
        wx.showModal({
          title:"错误",
          content: "账号格式有误"
        })
        that.isaccountNumber = false;
    }
    else 
    {
      that.isaccountNumber = true;
    }
    
  
    //正则表达式
    if(!/([0-9A-Za-z]{6,16}$)/.test(this.data.password))
    {
        wx.showModal({
            title:"错误",
            content:"密码格式不正确"
        });
        that.ispassword=false;
    }
    else
    {
        that.ispassword=true;
    }
    if(that.data.email=="")
    {
        wx.showModal({
            title:"错误",
            content:"邮箱不能为空"
        });
        that.isemail=false;
    }
   
    else if(! (/^\w+((-\w+)|(\.\w+))*@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(that.data.email))
    {
        wx.showModal({
            title:"错误",
            content:"邮箱格式出错"
        });
        that.isemail=false;
    }    
    else
    {
        that.isemail=true;
    }


    if(that.isaccountNumber&&that.ispassword&&that.isemail)
    {
        wx.request({
            url: 'http://localhost:8080/api/v1/users',
            data:{
                accountNumber:that.data.accountNumber,
                password:that.data.password,
                email:that.data.email
            },
            method:"POST",
            header:{
              'content-type': 'application/x-www-form-urlencoded' // 默认值
            },
            success:function success(res){
                wx.navigateTo({
                  url: '/pages/login/login',
                });
            }
        });
    }
  }
});
